/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2011
 */

package com.nail.zhaogr.dao;

import javacommon.base.BaseHibernateDao;

import org.springframework.stereotype.Repository;

import cn.org.rapid_framework.page.Page;

import com.nail.zhaogr.model.PublishInfo;
import com.nail.zhaogr.vo.query.PublishInfoQuery;

@Repository
public class PublishInfoDao extends BaseHibernateDao<PublishInfo,java.lang.Long>{

	public Class getEntityClass() {
		return PublishInfo.class;
	}
	
	public Page findPage(PublishInfoQuery query) {
        //XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
        // [column]为字符串拼接, {column}为使用占位符. [column]为使用字符串拼接,如username='[username]',偷懒时可以使用字符串拼接 
        // [column] 为PageRequest的属性
		String sql ="";
		if(query.getCityId()==null){
			sql = "select t from PublishInfo t where  1=1 "
			
				+ "/~ and t.memberId = '[memberId]' ~/"
				+ "/~ and t.categoryId = '[categoryId]' ~/"
				//+ "/~ and t.cityId = '[cityId]' ~/"
				+ "/~ and t.phone = '[phone]' ~/"
				+ "/~ and t.address = '[address]' ~/"
				+ "/~ and t.tag = '[tag]' ~/"
				+ "/~ and t.status = '[status]' ~/"
				+ "/~ and t.level = '[level]' ~/"
				+ "/~ and t.credit = '[credit]' ~/"
				+ "/~ and t.images = '[images]' ~/"
				+ "/~ and t.photo = '[photo]' ~/"
				+ "/~ and t.idPhoto = '[idPhoto]' ~/"
				+ "/~ and t.goodRate = '[goodRate]' ~/"
				+ "/~ and t.commentCount = '[commentCount]' ~/"
				+ "/~ and t.createDate = '[createDate]' ~/"
				+ "/~ and t.updateTime = '[updateTime]' ~/"
				+ "/~ and t.lastCommentId = '[lastCommentId]' ~/"
				+ "/~ and t.parentCityId = '[parentCityId]' ~/"
				+ "/~ and t.serviceArea like '%[serviceArea]%' ~/"
				+ "/~ and ( t.cityOne like '%[cityOne]%' ~/"
				+ "/~ or t.cityTwo like '%[cityTwo]%' ~/"
				+ "/~ or t.cityThree like '%[cityThree]%' ~/"
				+ "/~ or t.profile like '%[profile]%' ) ~/"
				+ "/~ order by [sortColumns] ~/";
		}else{
			sql = "select t from PublishInfo t,PsnServiceArea p where  t.publishInfoId=p.publishInfoId  "
				+ "/~ and p.cityId = '[cityId]' ~/" 
				+ "/~ and t.memberId = '[memberId]' ~/"
				+ "/~ and t.categoryId = '[categoryId]' ~/"
				//+ "/~ and t.cityId = '[cityId]' ~/"
				+ "/~ and t.phone = '[phone]' ~/"
				+ "/~ and t.address = '[address]' ~/"
				+ "/~ and t.tag = '[tag]' ~/"
				+ "/~ and t.status = '[status]' ~/"
				+ "/~ and t.level = '[level]' ~/"
				+ "/~ and t.credit = '[credit]' ~/"
				+ "/~ and t.images = '[images]' ~/"
				+ "/~ and t.photo = '[photo]' ~/"
				+ "/~ and t.idPhoto = '[idPhoto]' ~/"
				+ "/~ and t.goodRate = '[goodRate]' ~/"
				+ "/~ and t.commentCount = '[commentCount]' ~/"
				+ "/~ and t.createDate = '[createDate]' ~/"
				+ "/~ and t.updateTime = '[updateTime]' ~/"
				+ "/~ and t.lastCommentId = '[lastCommentId]' ~/"
				+ "/~ and t.parentCityId = '[parentCityId]' ~/"
				+ "/~ and t.serviceArea like '%[serviceArea]%' ~/"
				+ "/~ and ( t.cityOne like '%[cityOne]%' ~/"
				+ "/~ or t.cityTwo like '%[cityTwo]%' ~/"
				+ "/~ or t.cityThree like '%[cityThree]%' ~/"
				+ "/~ or t.profile like '%[profile]%' ) ~/"
				+ "/~ order by [sortColumns] ~/";
		}
		return pageQuery(sql,query);
	}
	

}
